package com.lhl.p6spy.domain.entity;

import com.lhl.fw.db.entity.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class Student extends BaseEntity<String> {

	private String name;
	@ManyToMany(cascade=CascadeType.ALL,fetch=FetchType.LAZY)
	@JoinTable(name = "TEACHER_STUDENT")
	private Set<Teacher> teachers = new HashSet<>();
	
	public void addTeacher(Teacher teacher) {
		this.teachers.add(teacher);
		teacher.getStudents().add(this);
	}
	public void removeTeacher(Teacher teacher) {
		if(this.teachers.contains(teacher)) {
			this.teachers.remove(teacher);
		}
	}
}
